package com.jlusoft.spd.po.quartz;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.jlusoft.spd.mybatis.dao.StudentCourseDao;
import com.jlusoft.spd.mybatis.dao.StudentInfoDao;
import com.jlusoft.spd.po.StudentCourse;
import com.jlusoft.spd.po.StudentInfo;

@Component
@Transactional
public class QuartzTimeJob {
	private static final Logger logger = LoggerFactory
			.getLogger(QuartzTimeJob.class);
	@Autowired
	private StudentInfoDao studentInfoDao;
	@Autowired
	private StudentCourseDao studentCourseDao;

	/**
	 * 当天生日
	 */
	public void testCallBirthday() {
		logger.info("testCallBirthday begin ...");
		List<StudentInfo> studentInfoList = studentInfoDao.callBirthday();
		if (null == studentInfoList) {
			System.out.println("Result Is Null !");
		} else {
			System.out.println("Result Size Is :" + studentInfoList.size());
			for (StudentInfo s : studentInfoList) {
				System.out.println("=" + s.getClassName() + "--"
						+ s.getDepartmentName() + "--" + s.getStudentName());
			}
		}
		logger.info("testCallBirthday end ...");
	}

	/**
	 * 课程表
	 */
	public void testCallDateKb() {
		logger.info("testCallDateKb begin ...");
		Date date = getDateByStr("2012-05-29", "yyyy-MM-dd");
		String className = "1B11111";
		String atanza = null;
		List<StudentCourse> studentInfoList = studentCourseDao
				.finaStudentCourse(date, className, atanza);
		if (null == studentInfoList) {
			System.out.println("Result Is Null !");
		} else {
			System.out.println("Result Size Is :" + studentInfoList.size());
			for (StudentCourse s : studentInfoList) {
				System.out.println("=" + s.getClassName() + "--"
						+ s.getClassRoom() + "--" + s.getCourseName() + "--"
						+ s.getCourseTeacher());
			}
		}
		logger.info("testCallDateKb end ...");
	}

	public Date getDateByStr(String str, String format) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		Date date = null;
		try {
			date = dateFormat.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}
}
